package com.zzx.boot.servlet.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzx.boot.entity.table.Blacklist;
import com.zzx.boot.mapper.BlacklistMapper;
import com.zzx.boot.servlet.BlacklistService;
import com.zzx.boot.utils.DateTImeUtils;
import com.zzx.boot.utils.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 * @author tan
 * @version 1.0
 * @date 2023/7/10 23:55
 */
@Service
public class BlacklistServiceImpl extends ServiceImpl<BlacklistMapper, Blacklist> implements BlacklistService {
    @Override
    public String addBlack(Long blackId) {
        Long id = SecurityUtils.getUserId();
        int i = baseMapper.insert(new Blacklist(null, blackId, id, DateTImeUtils.getDate()));
        return i==1?"拉黑成功":"拉黑失败";
    }

    @Override
    public String removeBlack(Long blackId) {
        Long id = SecurityUtils.getUserId();
        LambdaQueryWrapper<Blacklist> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Blacklist::getBlackId,blackId);
        wrapper.eq(Blacklist::getUserId,id);
        int i = baseMapper.delete(wrapper);
        return i==1?"取消拉黑成功":"取消拉黑失败";
    }
}
